import {splitStandard} from '@/libs/standardUtils'
import {CnNormalSpan} from '../text'

export const StandardText = defineComponent({
  props: {
    standard: String,
    paramUnit: String
  },
  setup(props, ctx) {
    const standardSplit = computed(() => splitStandard(props.standard))

    return () => (
      <CnNormalSpan>
        {{
          default: () => {
            if (standardSplit.value.value.length <= 1) {
              return [
                standardSplit.value.cnUnit ? (
                  <CnNormalSpan class='mr-16'>{standardSplit.value.cnUnit}</CnNormalSpan>
                ) : null,
                <CnNormalSpan class='mr-16'>{standardSplit.value.value[0] || '--'}</CnNormalSpan>,
                <CnNormalSpan>
                  {standardSplit.value.value[0] ? props.paramUnit || '' : ''}
                </CnNormalSpan>
              ]
            } else {
              return [
                <CnNormalSpan>{standardSplit.value.value[0] || '--'}</CnNormalSpan>,
                <CnNormalSpan class='mr-16'>
                  {standardSplit.value.value[0] ? props.paramUnit || '' : ''}
                </CnNormalSpan>,
                <CnNormalSpan class='mr-16'>{standardSplit.value.unit}</CnNormalSpan>,
                <CnNormalSpan>{standardSplit.value.value[1] || '--'}</CnNormalSpan>,
                <CnNormalSpan>
                  {standardSplit.value.value[1] ? props.paramUnit || '' : ''}
                </CnNormalSpan>
              ]
            }
          }
        }}
      </CnNormalSpan>
    )
  }
})
